require(['./config'], () => {
  require(['cookie', 'header', 'footer'], (cookie) => {
    class Login {
      constructor() {
        this.login();
      }

      login() {
        $('.login-btn').on('click', () => {
          const name = $('#username').val();
          const pwd = $('#userpwd').val();
          let userList = JSON.parse(localStorage.getItem('userList'));
          if (userList) {
            let isTrue = userList.some((user) => user.name === name && user.pwd === pwd );
            if (isTrue) {
              $.cookie('name', name, { path: '/' });
              alert('登陆成功，即将返回首页');
              location.href='/index.html';
            } else {
              alert('用户名或者密码错误,请重新登录!');
              $('#username').val('');
              $('#userpwd').val('');
            }
          }else{
            alert('还没有用户，先去注册');
            $('#username').val('');
            $('#userpwd').val('');
            location.replace('/html/register.html');
          }
        })
      }

    }
    new Login()
  })
})